package com.gzsxy.esjy.service.product.filter;

import cn.hutool.core.util.ReflectUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.gzsxy.esjy.redis.user.ISystemUser;
import lombok.Data;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 返回登录成功token外加用户信息
 * @date 2021/11/15 14:16
 */
@Data
public class DefaultUser  implements ISystemUser {

    /**
     * token
     */
    @JSONField(name = "access_token")
    private String accessToken;

    /**
     * token类型
     */
    @JSONField(name = "token_type")
    private String tokenType;

    /**
     * 刷新token
     */
    @JSONField(name = "refresh_token")
    private String refreshToken;

    /**
     * 有效时间
     */
    @JSONField(name = "expires_in")
    private long expiresIn;

    /**
     * 截止时间 = expiresIn +当前时间
     */
    private long expiresBy;

    /**
     * 用户名
     */
    @JSONField(name = "userName")
    private String userName;

    /**
     * 真实名字
     */
    @JSONField(name = "realName")
    private String realName;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 最后一次登录时间
     */
    private Date lastLoginTime;

    /**
     * 角色代码
     */
    @JSONField(name = "roleIds")
    private String roleIds;

    /**
     * 客户端id
     */
    private String clientId;

    /**
     * 是否为系统管理员
     */
    @JSONField(name = "isAdmin")
    private Boolean isAdmin;

    /**
     * 用户id
     */
    @JSONField(name = "id")
    private String id;

    /**
     * 头部信息=tokenType+“ ”+access_token
     */
    private String authorization;




    @Override
    public String getUserName() {
        return this.userName;
    }

    @Override
    public String getUserAccout() {
        return this.userName;
    }


    @Override
    public List<String> getRoles() {
        if (this.roleIds == null){
            return null;
        }
        return Arrays.asList(this.roleIds.split(","));
    }

    @Override
    public Object get(String key, Object defValue) {
        Object fieldValue = ReflectUtil.getFieldValue(this, key);
        return null == fieldValue ? defValue :fieldValue;
    }

    @Override
    public <T> T get(String key, Class<T> clazz) {
        return null;
    }

    @Override
    public String getToken() {
        return this.accessToken;
    }

    @Override
    public Map<String, Object> getUserInfoMap() {
        return null;
    }
}
